/**************************************************************************(C)*
 *
 *  This file is part of the GreenHills project
 *  Copyright (C) 2009  TietoEnator
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************(C)*/

#pragma once

#include <QtCore/QAbstractTableModel>

#include "core/iroom.h"
#include "clientmvadll.h"


namespace greenhills {
namespace client {
namespace mva {

/** @brief Model View adapter for a room
 *
 * Provides data abstraction of room object
 */
class GH_CLIENTMVA_QT_CLASS CRoomModel : public QAbstractTableModel,
    public greenhills::core::IRoomListener
{
Q_OBJECT

public:
    enum eColumns
    {
        ColumnId,
        ColumnName,
        ColumnType,
        ColumnLatitude,
        ColumnLongitude,
        ColumnAltitude,
        ColumnTimeStamp,
        ColumnMovementSpeed,
        ColumnMovementDirection,
        ECOLUMNS_COUNT
    };

public:
    CRoomModel(greenhills::core::IRoom *pRoom);
    virtual ~CRoomModel();

public: //QAbstractTableModel
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QModelIndex index(int row, int column, const QModelIndex &parent
            = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role
            = Qt::DisplayRole) const;

private:
    virtual void aboutToAddItem(greenhills::core::IRoom *pRoom,
                           const greenhills::core::CItemId &pItemId);
    virtual void aboutToUpdateItem(greenhills::core::IRoom *pRoom,
                             const greenhills::core::CItemId &pItemId);
    virtual void aboutToRemoveItem(greenhills::core::IRoom *pRoom,
                             const greenhills::core::CItemId &pItemId);

    virtual void itemAdded(greenhills::core::IRoom *pRoom,
                           const greenhills::core::CItemId &pItemId,
                           const std::string &pItemName,
                           const greenhills::core::CItemType &pItemType);
    virtual void itemUpdated(greenhills::core::IRoom *pRoom,
                             const greenhills::core::CItemId &pItemId,
                             const unsigned char *pData,
                             unsigned int pLength);
    virtual void itemRemoved(greenhills::core::IRoom *pRoom,
                             const greenhills::core::CItemId &pItemId);

private:
    greenhills::core::IRoom *mRoom;
};

} //namespace mva
} //namespace client
} //namespace greenhills
